package ModelLayer;


/**
 * Class Item is a class representing shared characteristics of the different item types..
 *
 * @author  Mie P., Danny M.P., Jakob K., Anna K., Anders A.P.  
 * @version 1.0
 */
public abstract class Item {

    private static int counter;
    private int        itemID;
    private String     name;
    private String     description;
    private double     salesPrice;

    /**
     * Constructor for superclass Item.
     * 
     * @param name          Name of the item.
     * @param description   Description of the item.
     */
    public Item(String name, String description) {

        ++this.counter;
        itemID = counter;
        setName(name);
        setDescription(description);
        salesPrice = -1;

    }

    /**
     * Update name and description.
     * 
     * @param name          Name of the item.
     * @param description   Description of the item.
     */
    public void updateItem(String name, String description) {

        setName(name);
        setDescription(description);

    }
    
    /**
     * Set the name.
     * 
     * @param input     Name of the item.
     */
    private void setName(String input) {

        name = input;

    }
    
    /**
     * Set the description.
     * 
     * @param input     Description of the item.
     */
    private void setDescription(String input) {

        description = input;

    }
    
    /**
     * Set the salesPrice.
     * 
     * @param input     Sales price of the item.
     */
    public void setSalesPrice(double input) {

        salesPrice = input;

    }
    
    /**
     * Accessor method for itemID.
     * 
     * @return The value of the itemID.
     */
    public int getID() {

        return this.itemID;

    }
    
    /**
     * Accessor method for name.
     * 
     * @return The value of the name.
     */
    public String getName() {

        return this.name;

    }
    
    /**
     * Accessor method for description.
     * 
     * @return The value of the description.
     */
    public String getDescription() {

        return this.description;

    }

    /**
     * Accessor method for salesPrice.
     * 
     * @return              The value of the salesPrice.
     * @throws Exception    If the salesPrice is not set.
     */
    public double getSalesPrice() throws Exception {

        if (this.salesPrice != -1) {
            return this.salesPrice;
        }
        else {
            throw new IllegalArgumentException("Prisen på produktet er ikke sat");
        }

    }
    
    /**
     * Method for compare two Item objects. If both name and description
     * of the objects are the same, is the two objects declared for being the same.
     */
    @Override
    public boolean equals(Object obj) {

        boolean isEqual = false;
        if (obj == null) {
            isEqual = false;
        }
        if (!(obj instanceof Item)) {
            isEqual = false;
        }
        Item other = (Item) obj;
        if (this.getName().equals(other.getName()) && 
            this.getDescription().equals(other.getDescription())) {
            isEqual = true;
        }
        return isEqual;

    }
    
}